package com.winhxd.b2c.pay.controller;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.pay.condition.PayPreOrderCondition;
import com.winhxd.b2c.common.domain.pay.condition.PayRefundCondition;
import com.winhxd.b2c.common.domain.pay.condition.PayTransfersToWxBankCondition;
import com.winhxd.b2c.common.domain.pay.condition.PayTransfersToWxChangeCondition;
import com.winhxd.b2c.common.domain.pay.vo.PayPreOrderVO;
import com.winhxd.b2c.common.domain.pay.vo.PayRefundVO;
import com.winhxd.b2c.common.domain.pay.vo.PayTransfersToWxBankVO;
import com.winhxd.b2c.common.domain.pay.vo.PayTransfersToWxChangeVO;
import com.winhxd.b2c.common.feign.pay.PayServiceClient;
import com.winhxd.b2c.pay.weixin.service.WXRefundService;
import com.winhxd.b2c.pay.weixin.service.WXTransfersService;
import com.winhxd.b2c.pay.weixin.service.WXUnifiedOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "ApiPay")
@RestController
public class PayController implements PayServiceClient {

	private static final Logger logger = LoggerFactory.getLogger(PayController.class);

	@Autowired
	private WXUnifiedOrderService unifiedOrderService;

	@Autowired
	private WXRefundService refundService;

	@Autowired
	private WXTransfersService transfersService;
	
	/**
	 * @author liuhanning
	 * @date  2018年8月20日 上午11:32:47
	 * @Description 支付
	 * @param condition
	 * @return
	 */
	@Override
	public ResponseResult<PayPreOrderVO> prePay(@RequestBody PayPreOrderCondition condition){
		PayPreOrderVO vo = unifiedOrderService.unifiedOrder(condition);
		ResponseResult<PayPreOrderVO> result=new ResponseResult<>();
		result.setData(vo);
		return result;
	}
	/**
	 * @author liuhanning
	 * @date  2018年8月20日 上午11:32:47
	 * @Description 退款
	 * @param condition
	 * @return
	 */
	@Override
	public ResponseResult<PayRefundVO> orderRefund(@RequestBody PayRefundCondition condition){
		PayRefundVO payRefund = refundService.refundOrder(condition);
		ResponseResult<PayRefundVO> result = new ResponseResult<>();
		result.setData(payRefund);
		return result;
	}
	@Override
	public ResponseResult<PayTransfersToWxChangeVO> transfersToChange(@RequestBody PayTransfersToWxChangeCondition condition){
		PayTransfersToWxChangeVO payTransfersToWxChange = transfersService.transfersToChange(condition);
		ResponseResult<PayTransfersToWxChangeVO> result = new ResponseResult<>();
		result.setData(payTransfersToWxChange);
		return result;
	}
	@Override
	public ResponseResult<PayTransfersToWxBankVO> transfersToBank(@RequestBody PayTransfersToWxBankCondition condition){
		//PayTransfersToWxBankVO payTransfersToWxBank = transfersService.transfersToBank(condition);
		ResponseResult<PayTransfersToWxBankVO> result=new ResponseResult<>();
		//result.setData(payTransfersToWxBank);
		return result;
	}

	@Override
	@ApiOperation(value = "轮询确认转账到银行卡记录状态", notes = "轮询确认转账到银行卡记录状态")
	@ApiResponses({@ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常")})
	public ResponseResult<Integer> confirmTransferToBankStatus() throws Exception {
		ResponseResult<Integer> result=new ResponseResult<>();
		//Integer data=payService.confirmTransferToBankStatus();
		//result.setData(data);
		return result;
	}
}
